package com.qf.listener;

import com.qf.pojo.Hz;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/29 17:32
 */
@Component
//开启异步,一个类开启扫描的包的范围内的其他类也自动开启
@EnableAsync
public class Xf {
//    事件监听器,只要发布事件的参数和方法参数一致自动调用
    @EventListener
    @Async
    public void onEvent(Hz hz){

        try {
            Thread.sleep(5000);
            System.out.println("消防员收到了"+hz.getAddress()+"发生了特大火灾啊"+Thread.currentThread().getName());

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
